﻿using AutoMapper;
using MRSite.AutoMapper.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace MRSite.AutoMapper.Extensions
{
    internal static class AutoMapperExtensions
    {
        public static T MapTo<T>(this object source)
        {
            return Mapper.Map<T>(source);
        }

        public static T MapTo<TSource, T>(this TSource source, T destination)
        {
            return Mapper.Map(source, destination);
        }

        public static void CreateAutoAttributeMaps(
            this IMapperConfigurationExpression mapperConfigurationExpression, Type type)
        {
            foreach (var item in type.GetTypeInfo().GetCustomAttributes<BaseMapAttribute>())
            {
                item.CreateMap(mapperConfigurationExpression, type);
            }
        }
    }
}
